.PHONY: default build run help project1

MAINCLASS=cz.cuni.amis.pogamut.episodic.lispbots.LispBotMain
MVNOPTS=-f LispBots/pom.xml
MVNMEMOPTS=-f EpisBotMemory/pom.xml

PLOTTMP=plot.dat

default: build

build:
	mvn $(MVNMEMOPTS) install
	mvn $(MVNOPTS) install

# Clean all targets.
clean:
	mvn $(MVNMEMOPTS) clean
	mvn $(MVNOPTS) clean

# Run with some sane opts
run: build
	mvn $(MVNOPTS) exec:java -Dexec.mainClass=$(MAINCLASS) -Dexec.args="-e LispBots/default.lisp -d LispBots/default.desc"


# Debugging: start a debug-enabled suspended VM and wait for connection
# TODO: Doesn't work.
#DBG_PORT=8000
#debug:
#	mvn $(MVNOPTS) exec:exec -Dexec.executable="java" -Dexec.as="-classpath %classpath -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=$(DBG_PORT) $(MAINCLASS)"

# Experiment #1
E1_PLANNINGDOMAIN=longlife
# 70 years of generated episode
E1_PLANNINGLENGTH=23520
# Let's not get crazy about simulations at this length. They take forever and graphs aren't very helpful.
E1_TIMELIMIT=10000
# ~44 years
#E1_TIMELIMIT=14000
E1_DATA=Experiment1Data.lisp
E1_DESC=Experiment1Desc.desc
E1_ARGS="-x 1 -d $(E1_DESC) -e $(E1_DATA) -t $(E1_TIMELIMIT)"
E1_LOG=Experiment1.csv

$(E1_DATA): episode-planner/$(E1_PLANNINGDOMAIN)/plib.lisp
	echo "Creating input data"
	cd episode-planner; \
	clisp -C create-corpus.lisp $(E1_PLANNINGDOMAIN) $(E1_PLANNINGLENGTH) |grep "^creating session"
	echo "Creating domain descriptor"
	cd episode-planner; \
	./domainsummary.sh $(E1_PLANNINGDOMAIN) > ../$(E1_DESC)
	cat episode-planner/$(E1_PLANNINGDOMAIN)_corpus.txt > $(E1_DATA)

experiment1: $(E1_DATA) build
	echo "Running experiment"
	mvn $(MVNOPTS) exec:java -Dexec.mainClass=$(MAINCLASS) -Dexec.args=$(E1_ARGS) | tee $(E1_LOG)
	sh Makefile.plothelper.sh $(E1_LOG) "1"

# Experiment #2
E2_PLANNINGDOMAIN1=longlife
E2_PLANNINGDOMAIN2=longlife/retention
# 13 years; 10 init, 1 pre, 1 testing, 1 post
E2_PLANNINGLENGTH1=10079
E2_PLANNINGLENGTH2=2015
E2_DATA=Experiment2Data.lisp
E2_DESC=Experiment2Desc.desc
E2_ARGS="-x 2 -d $(E2_DESC) -e $(E2_DATA)"
E2_LOG=Experiment2.csv

# It is assumed that domain2 is a superset of domain1. Hence we just use descriptor for 2.
$(E2_DATA): episode-planner/$(E2_PLANNINGDOMAIN1)/plib.lisp episode-planner/$(E2_PLANNINGDOMAIN2)/plib.lisp
	echo "Creating init data"
	cd episode-planner; \
	clisp -C create-corpus.lisp $(E2_PLANNINGDOMAIN1) $(E2_PLANNINGLENGTH1) |grep "^creating session"
	echo "Creating test data"
	cd episode-planner; \
	clisp -C create-corpus.lisp $(E2_PLANNINGDOMAIN2) $(E2_PLANNINGLENGTH2) |grep "^creating session"
	echo "Creating domain descriptor"
	cd episode-planner; \
	./domainsummary.sh $(E2_PLANNINGDOMAIN2) > ../$(E2_DESC)
	cat episode-planner/$(E2_PLANNINGDOMAIN2)_corpus.txt episode-planner/$(E2_PLANNINGDOMAIN2)_corpus.txt > $(E2_DATA)

experiment2: $(E2_DATA) build
	echo "Running experiment"
	mvn $(MVNOPTS) exec:java -Dexec.mainClass=$(MAINCLASS) -Dexec.args=$(E2_ARGS) | tee $(E2_LOG)

# Experiment #3
E3_PLANNINGDOMAIN=longlife/temporal
E3_PLANNINGLENGTH=2400
E3_TIMELIMIT=1176
E3_DATA=Experiment3Data.lisp
E3_DESC=Experiment3Desc.desc
E3_ARGS="-x 3 -d $(E3_DESC) -e $(E3_DATA) -t $(E3_TIMELIMIT)"
E3_LOG=Experiment3.csv

# It is assumed that domain2 is a superset of domain1. Hence we just use descriptor for 2.
$(E3_DATA): episode-planner/$(E3_PLANNINGDOMAIN)/plib.lisp
	echo "Creating test data"
	cd episode-planner; \
	clisp -C create-corpus.lisp $(E3_PLANNINGDOMAIN) $(E3_PLANNINGLENGTH) |grep "^creating session"
	echo "Creating domain descriptor"
	cd episode-planner; \
	./domainsummary.sh $(E3_PLANNINGDOMAIN) > ../$(E3_DESC)
	cat episode-planner/$(E3_PLANNINGDOMAIN)_corpus.txt > $(E3_DATA)

experiment3: $(E3_DATA) build
	echo "Running experiment"
	mvn $(MVNOPTS) exec:java -Dexec.mainClass=$(MAINCLASS) -Dexec.args=$(E3_ARGS) | tee $(E3_LOG)
	sh Makefile.plothelper.sh $(E3_LOG) "3"

# Experiment #4
E4_PLANNINGDOMAIN=longlife
# variable, up to 4 years
E4_PLANNINGLENGTH=10000
E4_TIMELIMIT=10000
E4_DATA=Experiment4Data.lisp
E4_DESC=Experiment4Desc.desc
E4_ARGS="-x 4 -d $(E4_DESC) -e $(E4_DATA) -t $(E4_TIMELIMIT)"
E4_LOG=Experiment4.csv

# It is assumed that domain2 is a superset of domain1. Hence we just use descriptor for 2.
$(E4_DATA): episode-planner/$(E4_PLANNINGDOMAIN)/plib.lisp
	echo "Creating test data"
	cd episode-planner; \
	clisp -C create-corpus.lisp $(E4_PLANNINGDOMAIN) $(E4_PLANNINGLENGTH) |grep "^creating session"
	echo "Creating domain descriptor"
	cd episode-planner; \
	./domainsummary.sh $(E4_PLANNINGDOMAIN) > ../$(E4_DESC)
	cat episode-planner/$(E4_PLANNINGDOMAIN)_corpus.txt > $(E4_DATA)

experiment4: $(E4_DATA) build
	echo "Running experiment"
	mvn $(MVNOPTS) exec:java -Dexec.mainClass=$(MAINCLASS) -Dexec.args=$(E4_ARGS) | tee $(E4_LOG)
	sh Makefile.plothelper.sh $(E4_LOG) "4"

